package scrapygui;

import com.sun.istack.internal.NotNull;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;

class ViewUtils {


    static void showDialog(String s) {
        Alert alert = new Alert( Alert.AlertType.WARNING );
        alert.setTitle( "Warning" );
        alert.setContentText( s );
        alert.setHeaderText( null );
        alert.showAndWait();
    }

    private static Button createButton(String text, EventHandler<ActionEvent> call) {
        Button btn = new Button();
        btn.setMinWidth( 120 );
        btn.setText( text );
        btn.setOnAction( call );
        return btn;
    }

    static Button createRefreshButton(@NotNull EventHandler<ActionEvent> call) {
        return createButton("Refresh", call );
    }

    static Button createStartAllButton(List<DeviceBean> list, Consumer<String> call) {
        return createButton("Start All", event -> {
            for (DeviceBean bean : list) {
                call.accept( bean.getVia() );
            }
        });
    }

    static Button createDeviceButton(@NotNull DeviceBean bean, Consumer<String> call) {
        return createButton( bean.getModel(), event -> call.accept( bean.getVia() ) );
    }
}
